package handler

import (
	"cloudDevice2/sampleapi/model"

	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"

	"github.com/labstack/echo"
)

func UploadCallLog(context echo.Context) error {
	var resp model.ResponseCode
	request_data := new(model.DeviceCallLogs)
	bodyData, err := ioutil.ReadAll(context.Request().Body)
	if err != nil {
		resp = model.ResponseCode{ReturnCode: 10002}
		return context.JSON(http.StatusOK, resp)
	}
	log.Println(fmt.Sprintf("UploadCallLog: %s", string(bodyData)))
	err = json.Unmarshal(bodyData, request_data)
	if err != nil {
		resp = model.ResponseCode{ReturnCode: 10002}
		return context.JSON(http.StatusOK, resp)
	}

	return context.JSON(http.StatusOK, model.ResponseCode{ReturnCode: 0})
}
